<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of RegistionAction
 *
 * @author Alen
 */
class RegistionAction extends PyramidAction {
    //put your code here
    public function index(){
        $this->display();
    }
    
    public function save(){$this->dm=new SoDataModule();
        $this->dm->tablename='tusermember';
	$this->dm->add_param('UserName',request_string('username'),'手机号码未填写');
	$this->dm->add_param('Password',request_string('password'),'登录密码未填写');
	$this->dm->compare_param(request_string('password'),request_string('repassword'),'两次密码输入不一致');
	if($this->dm->get_error()) redirect($this->dm->get_error());
        
	// 判断用户名是否重复
        if($this->dm->select_value('tusermember', 'UserName=\''.$this->dm->UserName.'\'','count(ID)'))redirect('用户帐号已存在,请重新选择用户名!');
        
        // 判断上家是否存在
	$referrer=request_string('referrer');
	if($referrer && !$this->dm->select_value('tusermember','UserName=\''.$referrer.'\'','count(ID)')) redirect('推荐人['.$referrer.']不存在');
	
	$this->dm->add_param('RegistIP',  get_client_ip());
	$this->dm->add_param('MobileNumber',$this->dm->UserName);
	$this->dm->add_param('ReferrerName',$referrer?$referrer:'system');
	$this->dm->add_param('State',1,'int');
	if($this->dm->insert()){
                if(!$this->biz) $this->biz=new SoBizCommon();
                $this->biz->user_login_test($this->dm->UserName);
		redirect('注册成功','?m=UC_Index');
	}else{
		redirect('注册失败:'.$this->dm->get_error());	
	}
    }
}

?>
